package org.jader.bolao;

import java.util.HashSet;
import java.util.Set;

import org.jader.bolao.gui.Application;

public class ChampionshipFactory {
	
	private ChampionshipFactory() {}
	
	public static Set<Integer> possibleNumberOfTeams(Phase p) {
		Championship c = p.championship();
		Set<Integer> possibilities = new HashSet<Integer>();
		int phaseIndex = c.indexOfPhase(p);
		if (phaseIndex > 0) {
			int maxNumberOfTeams = c.getPhase(phaseIndex-1).numberOfTeams();
			int numberOfGroups = c.getPhase(phaseIndex-1).numberOfGroups();
			int teams = 1;
			while (++teams < maxNumberOfTeams) {
				if (teams % numberOfGroups == 0) {
					possibilities.add(new Integer(teams));
				}
			}
			if (Application.DEBUG_MODE) System.out.println("ChampionshipFactory::possibleNumberOfTeams() => maxTeams: "+maxNumberOfTeams+"  numberOfGroups: "+numberOfGroups+"  possibilities: "+possibilities);
		}
		return possibilities;
	}
	
	public static Set<Integer> possibleNumberOfGroups(int numberOfTeams) {
		Set<Integer> possibilities = new HashSet<Integer>();
		for (int numberOfGroups=1; numberOfGroups<numberOfTeams; numberOfGroups++) {
			if (numberOfTeams % numberOfGroups == 0 &&
					numberOfTeams / numberOfGroups >= 2)
				possibilities.add(new Integer(numberOfGroups));
		}
		if (Application.DEBUG_MODE) System.out.println("ChampionshipFactory::possibleNumberOfGrous() => numberOfTeams: "+numberOfTeams+"  possibilities: "+possibilities);
		return possibilities;
	}

}
